/*
 * This file is part of aion-engine <aion-engine.com>
 *
 * aion-engine is private software: you can redistribute it and or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Private Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with aion-engine.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.model.templates.zone;

import com.aionengine.gameserver.dataholders.DataManager;
import com.aionengine.gameserver.geoEngine.bounding.BoundingBox;
import com.aionengine.gameserver.geoEngine.math.Vector3f;
import com.aionengine.gameserver.geoEngine.scene.Spatial;

/**
 * @author Rolandas
 */
public class MaterialZoneTemplate extends ZoneTemplate {

    public MaterialZoneTemplate(Spatial geometry, int mapId) {
        mapid = mapId;
        flags = DataManager.WORLD_MAPS_DATA.getTemplate(mapId).getFlags();
        setXmlName(geometry.getName() + "_" + mapId);
        BoundingBox box = (BoundingBox) geometry.getWorldBound();
        Vector3f center = box.getCenter();
        // don't use polygons for small areas, they are bugged in Java API
        if (geometry.getName().indexOf("CYLINDER") != -1 || geometry.getName().indexOf("CONE") != -1 ||
                geometry.getName().indexOf("H_COLUME") != -1) {
            areaType = AreaType.CYLINDER;
            cylinder = new Cylinder(center.x, center.y, Math.max(box.getXExtent(), box.getYExtent() + 1), center.z + box.getZExtent() + 1, center.z
                    - box.getZExtent() - 1);
        } else if (geometry.getName().indexOf("SEMISPHERE") != -1) {
            areaType = AreaType.SEMISPHERE;
            semisphere = new Semisphere(center.x, center.y, center.z, Math.max(Math.max(box.getXExtent(), box.getYExtent()), box.getZExtent()) + 1);
        } else {
            areaType = AreaType.SPHERE;
            sphere = new Sphere(center.x, center.y, center.z, Math.max(Math.max(box.getXExtent(), box.getYExtent()), box.getZExtent()) + 1);
        }
    }

}
